home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
v10n17.arc
/
OWNERDRW.ARC
/
OWNERDRW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-25
|
7KB
|
200 lines
/*----------------------------------------------
OWNERDRW.C -- Owner Draw Button Demo Program
(c) Charles Petzold, 1991
----------------------------------------------*/
#include <windows.h>
#include "ownerdrw.h"
long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
HANDLE hInst ;
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName [] = "OwnerDrw" ;
MSG msg;
HWND hwnd ;
WNDCLASS wndclass ;
hInst = hInstance ;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow (szAppName, "Onwer Draw Button Demo",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
BOOL FAR PASCAL ExitDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
{
static HBITMAP hbmOk, hbmCan ;
BITMAP bm ;
HBITMAP hbm ;
HBRUSH hBrush ;
HDC hdcMemory ;
HPEN hPen ;
LPDRAWITEMSTRUCT lpdis ;
switch (message)
{
case WM_INITDIALOG:
hbmOk = LoadBitmap (hInst, "OkBitmap") ;
hbmCan = LoadBitmap (hInst, "CancelBitmap") ;
return TRUE ;
case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT) lParam ;
switch (lpdis->CtlID)
{
case IDOK: hbm = hbmOk ; break ;
case IDCANCEL: hbm = hbmCan ; break ;
default: return FALSE ;
}
if (hbm != NULL)
{
GetObject (hbm, sizeof (BITMAP), (LPSTR) &bm) ;
hdcMemory = CreateCompatibleDC (lpdis->hDC) ;
SelectObject (hdcMemory, hbm) ;
StretchBlt (lpdis->hDC, 0, 0,
lpdis->rcItem.right, lpdis->rcItem.bottom,
hdcMemory, 0, 0, bm.bmWidth, bm.bmHeight,
lpdis->itemState & ODS_SELECTED ?
NOTSRCCOPY : SRCCOPY) ;
DeleteDC (hdcMemory) ;
}
if (lpdis->itemState & ODS_FOCUS)
{
hPen = SelectObject (lpdis->hDC,
CreatePen (PS_INSIDEFRAME,
(lpdis->rcItem.right + lpdis->rcItem.bottom) / 40,
RGB (255, 0, 0))) ;
hBrush = SelectObject (lpdis->hDC,
GetStockObject (NULL_BRUSH)) ;
Rectangle (lpdis->hDC, 0, 0, lpdis->rcItem.right,
lpdis->rcItem.bottom) ;
DeleteObject (SelectObject (lpdis->hDC, hPen)) ;
SelectObject (lpdis->hDC, hBrush) ;
}
return TRUE ;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
EndDialog (hDlg, TRUE) ;
return TRUE ;
case IDCANCEL:
EndDialog (hDlg, FALSE) ;
return TRUE ;
}
break ;
case WM_DESTROY:
DeleteObject (hbmOk) ;
DeleteObject (hbmCan) ;
return TRUE ;
}
return FALSE ;
}
BOOL FAR PASCAL AboutDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE ;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
EndDialog (hDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
static FARPROC lpfnExitDlgProc, lpfnAboutDlgProc ;
switch (message)
{
case WM_CREATE:
lpfnExitDlgProc = MakeProcInstance (ExitDlgProc, hInst) ;
lpfnAboutDlgProc = MakeProcInstance (AboutDlgProc, hInst) ;
return 0 ;
case WM_COMMAND:
switch (wParam)
{
case IDM_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
return 0 ;
case IDM_ABOUT:
DialogBox (hInst, "AboutBox", hwnd,
lpfnAboutDlgProc) ;
return 0 ;
}
break ;
case WM_CLOSE:
if (DialogBox (hInst, "ExitBox", hwnd, lpfnExitDlgProc))
DestroyWindow (hwnd) ;
return 0 ;
case WM_QUERYENDSESSION:
if (DialogBox (hInst, "ExitBox", hwnd, lpfnExitDlgProc))
return 1L ;
return 0 ;
case WM_DESTROY :
FreeProcInstance (lpfnExitDlgProc) ;
FreeProcInstance (lpfnAboutDlgProc) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}